package 购物;
import java.util.Scanner;
public class shoping {
    public static void main(String[] args) {

        product[] arr = new product[10];
       product apple = new product("苹果","水果",1,1000);
        product banana = new product("香蕉","水果",6,1000);
       product cole = new product("可乐","饮品",3,2000);
        product  juice= new product("果汁","饮品",4,12);
        product  xigua = new product("西瓜","水果",70,23);
         product  vegetable= new product("蔬菜","菜",68,45);
        product  tried= new product("劳累","身体状况",1,10000000);
          product difficult= new product("困难","解决",1,1000000);
        arr[0] = apple;
        arr[1] = banana;
        arr[2] = cole;
        arr[3] = juice;
        arr[4] = xigua;
        arr[5] = vegetable;
        arr[6] = tried;
        arr[7] = difficult;
        shopcar shopcar = new shopcar();
        while (true) {
            System.out.println("请选择操作：");
            System.out.println("1. 查看商品");
            System.out.println("2. 商品添加到购物车");
            System.out.println("3. 删除商品");
            System.out.println("4. 结算");
            System.out.println("5. 退出");
            String same2;
            Scanner scanner = new Scanner(System.in);
            int choice = scanner.nextInt();
            if (choice == 1) {
                System.out.println("商品列表：");
                for (int i = 0; i <= 7; i++) {
                    System.out.println(arr[i]);
                }
                break;
            }else if (choice == 2) {
                    do {
                        System.out.println("商品列表：");
                        for (int i = 0; i <= 7; i++) {
                            System.out.println(arr[i]);
                        }
                        Scanner scanner1 = new Scanner(System.in);
                        product xuanze=null;
                        System.out.println("请输入要添加的商品名称：");
                        String same = scanner1.nextLine();
                        if (same.equals("苹果")){
                           xuanze = apple;
                        };
                        if (same.equals("香蕉")){
                            xuanze = banana;
                        };
                        if (same.equals("可乐")){
                            xuanze = cole;
                        };
                        if (same.equals("果汁")){
                            xuanze = juice;
                        };
                        if (same.equals("西瓜")){
                            xuanze =xigua;
                        };
                        if (same.equals("劳累")) {
                            xuanze = tried;
                        }
                            if (same.equals("困难")){
                                xuanze = difficult;
                            };
                            if (same.equals("蔬菜")) {
                                xuanze = vegetable;
                            }
                        System.out.println("请输入要添加的数量：");
                        Scanner scanner2 = new Scanner(System.in);
                        int num = scanner2.nextInt();
                                shopcar.addproduct(xuanze,num);
                                System.out.println("商品已成功添加到购物车！");
                        System.out.println("是否继续购买？输入“停止”结束");
                        same2 = scanner.nextLine();
                    }while (!same2.equals("停止"));
                    break;
            }  else if (choice == 3) {
                System.out.println("请输入要删除的商品名称：");
                String delete = scanner.nextLine();
            } else if (choice == 4) {
                System.out.println("一共花多少钱");
                double totolprice=shopcar.Total();
                System.out.println("总价为: " + totolprice + "，下回敢来");
            } else if (choice == 5) {
                System.out.println("结束。");
                break;
            } else {
                System.out.println("请重新输入。");
            }
        }
    }
}
